package com.example.a02back.controller;

import com.example.a02back.common.APIResponse;
import com.example.a02back.service.impl.TopicServiceImpl;
import com.example.a02back.service.impl.TradeServiceImpl;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.AnnotatedParameterizedType;

/**
 * @ClassName SearchController
 * @Description
 * @Author SimpChaos
 * @Date 2022/7/21 2:13
 * @Version 1.0
 **/
@RestController
@Controller
@ResponseBody
@RequestMapping("/search")
public class SearchController {

    @Resource
    private TradeServiceImpl tradeService;
    @Resource
    private TopicServiceImpl topicService;



    /**
     * @Description: 
     * @Author: SimpChaos 
     * @Date: 2022/7/21 7:19
     * @Param: [httpServletRequest, httpServletResponse]
     * @Return: com.example.a02back.common.APIResponse<?>
     */
    @CrossOrigin
    @RequestMapping("/trade")
    public APIResponse<?> searchTrade(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse){
        String keyword = httpServletRequest.getParameter("keyword");
        return APIResponse.success("SUCCESS",tradeService.searchByKeyword(keyword));
    }


    /**
     * @Description: 
     * @Author: SimpChaos 
     * @Date: 2022/7/21 7:46
     * @Param: [httpServletRequest, httpServletResponse]
     * @Return: com.example.a02back.common.APIResponse<?>
     */
    @CrossOrigin
    @RequestMapping
    public APIResponse<?> searchTopic(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse){
        String keyword = httpServletRequest.getParameter("keyword");
        return APIResponse.success("SUCCESS",topicService.searchByKeyword(keyword));
    }


}
